/*
@STI LICENSE
(C) 2006-2008 Universit�t Innsbruck.

This file is part of myOntology.

myOntologyis free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

myOntologyis distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with myOntology.  If not, see <http://www.gnu.org/licenses/>.

@STI LICENSE */
/**
 * 
 */
package org.myontology.view.items;

import org.myontology.controller.AttributeHolder;
import org.myontology.model.Property;

/**
 * @author <a href="michael.hackl@sti2.at">Michael Hackl</a> Project:
 *         Myontology - www.myontology.org STI
 */
public class ComponentBuilder extends AbstractComponentBuilder {

	public ComponentBuilder(Property property, FormBuilder builder) {
		super(property, builder);
		titleBuilder = new TitleBuilder(property, builder);
		viewFieldBuilder = new SingleViewFieldBuilder(property, builder);
		editFieldBuilder = new SingleEditAreaBuilder(property,builder);
	}

	TitleBuilder titleBuilder;
	protected SingleViewFieldBuilder viewFieldBuilder;
	protected SingleEditAreaBuilder editFieldBuilder;

	public String getFieldInViewMode() {
		String ret = "";

		ret += titleBuilder.createTitle();

		String content = viewFieldBuilder.getFormInViewMode();

		// The field is printed in <div id=" fieldIdentifier "> and hence all
		// its components can be accessed with this
		ret += getFormContainer(content);
		ret = getFieldContainer(ret, CSSIDFIELD + property.getKey());

		return ret;
	}

	/**
	 * Returns the field in view mode.
	 * 
	 * @param id
	 * @param entry
	 * @return
	 */
	public String getFieldInEditMode(AttributeHolder attributes)
			 {
		String ret = "";
		ret += titleBuilder.createTitle();
		String content = editFieldBuilder.getFormInEditMode(attributes);
		ret += getFormContainer(content);
		ret = getFieldContainer(ret, CSSIDFIELD + property.getKey());

		return ret;
	}

	

	protected String getFieldContainer(String content, String divname) {

		String ret = "<div class=\"" + CSSCLASSFIELD + "\" id=\"" + divname
				+ "\">\n";
		ret += content;
		ret += "</div>\n\n";

		return ret;
	}

	protected String getFormContainer(String content) {
		String ret = "<div class=\"" + CSSCLASSCONTENT + "\" id=\""
				+ CSSIDCONTENT + property.getKey() + "\">\n";
		ret += content;
		ret += "</div>\n";

		return ret;
	}
}
